<?php

/**
 * Class of Policy Validate Machine
 *
 * @author BUI TIEN HIEP
 * @email bthiep@lhv.vn
 */
class PolicyValidateMachine {
    private $messages = array();//Store messages
    /**
     * Validate Expenses by Policies
     * @param type $policies
     * @param type $expenses
     */
    public function validate($policies,$expenses)
    {
        $bRet = false;
        foreach ($policies as $policy)
        {
            $validateInstance = ValidateFactory::getValidateInstance($policy);
            if($validateInstance->validate($expenses))
            {
                $bRet = true;
                $this->messages[] = $validateInstance->getMessage();
            }
        }
    }
    /**
     * Get message array
     * @return message array
     */
    public function getMessages()
    {
        return $this->messages;
    }
}
